﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject.Business;

namespace eProject.Web.UI.Admin
{
    public partial class CitiesManagementEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            loadData();
        }
        private void loadData() {
            int id = int.Parse(Request.QueryString["Id"].ToString());
            Cities city = new Cities(id);
            txtCitiesName.Text = city.Name;
            lblCreateDate.Text = city.CreatedDate.ToShortDateString();
            lblLastUpdate.Text = city.LastUpdate.ToShortDateString();
        }
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(this.Page_Load);
            this.btnSubmit.ServerClick += new EventHandler(btnSubmit_Click);
            this.btnReset.ServerClick += new EventHandler(btnReset_Click);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                int id = int.Parse(Request.QueryString["Id"].ToString());
                string Name = txtCitiesName.Text.Trim().ToString();
                DateTime lastedit = DateTime.Now;
                Cities city = new Cities(id);
                city.Name = Name;
                city.LastUpdate = lastedit;
                city.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Response.Redirect("AirportsManagementPro.aspx");
            //Response.Write(id);
        }
        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtCitiesName.Text = "";
        }
    }
}